package cn.java78.jdbc;

import cn.myschool.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class LimitSearch {
    public static void main(String[] args) {
        Connection con=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        Scanner sc=new Scanner(System.in);
        System.out.println("第几页?");
        int pageNo=sc.nextInt();
        System.out.println("页大小?");
        int pageSize=sc.nextInt();
        try {
            con= DBUtil.getConnection();
            ps=con.prepareStatement("select * from s_student order by stuno desc limit ?,?",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            ps.setInt(1,(pageNo-1)*pageSize);
            ps.setInt(2,pageSize);

            rs=ps.executeQuery();
            for(;rs.next();){
                System.out.println(rs.getLong("stuno")+","+rs.getString("sname"));

            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(rs,ps,con);
        }
    }
}
